from django import forms
from .models import *


class ProjectForm(forms.Form):
    name = forms.CharField(
        label="项目名称",
        widget=forms.TextInput(
            attrs={
                "placeholder": "Project Name",
                "class": "form-control"
            }
        ))
    desc = forms.CharField(
        label="项目描述",
        widget=forms.Textarea(
            attrs={
                "placeholder": "Description",
                "class": "form-control"
            }
        ))

    class Meta:
        model = Project
        fields = ('name', 'desc')


class InstanceForm(forms.Form):
    name = forms.CharField(
        widget=forms.TextInput(
            attrs={
                "placeholder": "Instance Name",
                "class": "form-control"
            }
        ))
    desc = forms.CharField(
        widget=forms.Textarea(
            attrs={
                "placeholder": "Description",
                "class": "form-control"
            }
        ))
    model = forms.ModelChoiceField(
        queryset=Model.objects.all(),
        widget=forms.Select(
            attrs={
                "placeholder": "Model",
                "class": "form-control"
            }
        )
    )
    method = forms.ChoiceField(
        choices=INSTANCE_METHODS,
        widget=forms.Select(
            attrs={
                "placeholder": "计算方法",
                "class": "form-control"
            }
        )
    )

    class Meta:
        model = Instance
        fields = ('name', 'desc', 'model_id', 'method')


class ModelForm(forms.Form):
    name = forms.CharField(
        label="模型名称",
        widget=forms.TextInput(
            attrs={
                "placeholder": "Model Name",
                "class": "form-control"
            }
        ))
    desc = forms.CharField(
        label="模型描述",
        widget=forms.Textarea(
            attrs={
                "placeholder": "Description",
                "class": "form-control"
            }
        ))
    context = forms.JSONField(
        label="模型内容（JSON格式）",
        widget=forms.Textarea(
            attrs={
                "placeholder": "Model Context",
                "class": "form-control"
            }
        )
    )
    type = forms.ChoiceField(
        choices=MODEL_TYPES,
        initial="private",
        widget=forms.Select(
            attrs={
                "placeholder": "类型",
                "class": "form-control"
            }
        )
    )

    class Meta:
        model = Model
        fields = ('name', 'desc', 'context', 'type')


class AlternativeForm(forms.Form):
    name = forms.CharField(
        widget=forms.TextInput(
            attrs={
                "placeholder": "Alternative Name",
                "class": "form-control"
            }
        ))
    desc = forms.CharField(
        widget=forms.Textarea(
            attrs={
                "placeholder": "Description",
                "class": "form-control"
            }
        ))

    class Meta:
        model = Alternative
        fields = ('name', 'desc')


class InstanceHasAlternativeForm(forms.Form):
    alternative = forms.ModelMultipleChoiceField(
        queryset=Alternative.objects.all(),
        widget=forms.Select(
            attrs={
                "placeholder": "Alternative",
                "class": "form-control"
            }
        )
    )


class NodeForm(forms.Form):
    parent_id = forms.ChoiceField(
        widget=forms.Select(
            attrs={
                "placeholder": "父结点编号",
                "class": "form-control"
            }
        ))
    name = forms.CharField(
        widget=forms.TextInput(
            attrs={
                "placeholder": "子结点名称",
                "class": "form-control"
            }
        ))
    type = forms.ChoiceField(
        choices=(('branch', '枝干结点'), ('leaf', '叶子结点'),),
        widget=forms.Select(
            attrs={
                "placeholder": "子结点类型",
                "class": "form-control"
            }
        ))
    desc = forms.CharField(
        widget=forms.Textarea(
            attrs={
                "placeholder": "子结点描述",
                "class": "form-control"
            }
        ))
